<?php

class m140520_090943_tbl_order_product extends CDbMigration
{
	public function up()
	{
        $this->createTable('tbl_order_product', array(
            'id'=>'pk',
            'order_id'=>'integer',
            'product_id'=>'integer'/*оповещение о новом объявлении*/
        ));

        $this->createIndex('order_id', 'tbl_order_product', 'order_id');
        $this->createIndex('product_id', 'tbl_order_product', 'product_id');

        $this->addForeignKey('fk_product', 'tbl_order_product', 'product_id', 'tbl_product', 'id', 'CASCADE', 'CASCADE');
        $this->addForeignKey('fk_order', 'tbl_order_product', 'order_id', 'tbl_order', 'id', 'CASCADE', 'CASCADE');

	}

	public function down()
	{
        $this->dropForeignKey('fk_product', 'tbl_order_product');
        $this->dropForeignKey('fk_order', 'tbl_order_product');
        $this->dropTable('tbl_order_product');
	}

	/*
	// Use safeUp/safeDown to do migration with transaction
	public function safeUp()
	{
	}

	public function safeDown()
	{
	}
	*/
}
